package com.atgion.manager.service.impl;

import cn.hutool.core.util.StrUtil;
import com.atgion.manager.mapper.SysOperationLogMapper;
import com.atgion.manager.service.SysOperationLogService;
import com.atgion.common.log.service.AsyncOperLogService;
import com.atgion.spzx.model.entity.system.SysOperationLog;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Slf4j
@Service
@RequiredArgsConstructor
public class SysOperationLogServiceImpl extends ServiceImpl<SysOperationLogMapper, SysOperationLog>
        implements SysOperationLogService , AsyncOperLogService {


    @Override
    public int clean() {
        return this.baseMapper.clean();
    }

    @Override
    public List<SysOperationLog> getExportList(SysOperationLog sysOperationLog) {
        return null;
    }

    @Override
    public IPage<SysOperationLog> getPage(Map<String, Object> params) {
        int pageSize = Integer.parseInt(String.valueOf(params.get("size")));
        int pageNum = Integer.parseInt(String.valueOf(params.get("current")));

        String businessType = (String) params.get("businessType");
        String description =  (String) params.get("createBy");
        String createTime =   (String) params.get("createTime[0]");
        String updateTime =   (String) params.get("createTime[1]");

        LambdaQueryWrapper<SysOperationLog> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StrUtil.isNotEmpty(businessType), SysOperationLog::getBusinessType, businessType);
        wrapper.like(StrUtil.isNotEmpty(description), SysOperationLog::getDescription, description);
        wrapper.ge(StrUtil.isNotEmpty(createTime), SysOperationLog::getCreateTime, createTime).le(StrUtil.isNotEmpty(updateTime), SysOperationLog::getUpdateTime, updateTime);

        IPage<SysOperationLog> sysUserPage = page(new Page<>(pageNum, pageSize), wrapper);

        return sysUserPage;
    }

    @Override
    public void saveSysOperLog(SysOperationLog sysOperLog) {
        System.out.println(sysOperLog);
        save(sysOperLog);
    }
}
